using System;
using Cinemachine;
using UnityEngine;

namespace Yoozoo.Core.Common
{
    public class FovQualityListener : QualityListenerMono<FovQualityListener.FovQualitySetting>
    {
        [SerializeField]
        private Camera _camera;
        [SerializeField]
        private CinemachineVirtualCamera _virtualCamera;
        
        [Serializable]
        public class FovQualitySetting : QualitySetting
        {
            [Range(0,180)]
            public int fov = 60;
        }

        protected override void Awake()
        {
            base.Awake();
            if (!_camera)
            {
                _camera = GetComponent<Camera>();
            }

            if (!_virtualCamera)
            {
                _virtualCamera = GetComponent<CinemachineVirtualCamera>();
            }
        }

        public override void ChangeQualitySetting(FovQualitySetting qualitySetting)
        {
            if (_camera)
            {
                _camera.fieldOfView = qualitySetting.fov;
            }

            if (_virtualCamera)
            {
                _virtualCamera.m_Lens.FieldOfView = qualitySetting.fov;
            }
        }
        
        
    }
}